<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  

  
  <title>搞定 Python 装饰器（一） | Laomo 的后院</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="来聊一聊 Python 中的一个很有意思的特性——装饰器  Python 装饰器，实际上是一个用于接收被装饰函数的一个可调用对象。  为什么说是可调用对象呢，因为在Python中，任何一个实现了__call__方法的对象都能被作为可调用对象，所以，装饰器可以是类，对象或者函数。 回到正题，装饰器实际上是Python的一个语法糖，当我们使用一个装饰器的时候，实际上在编译期间会被编译成为一个赋值语句。">
<meta property="og:type" content="article">
<meta property="og:title" content="搞定 Python 装饰器（一）">
<meta property="og:url" content="http://yoursite.com/2020/04/03/%E6%90%9E%E5%AE%9APython%E8%A3%85%E9%A5%B0%E5%99%A8%EF%BC%88%E4%B8%80%EF%BC%89/index.html">
<meta property="og:site_name" content="Laomo 的后院">
<meta property="og:description" content="来聊一聊 Python 中的一个很有意思的特性——装饰器  Python 装饰器，实际上是一个用于接收被装饰函数的一个可调用对象。  为什么说是可调用对象呢，因为在Python中，任何一个实现了__call__方法的对象都能被作为可调用对象，所以，装饰器可以是类，对象或者函数。 回到正题，装饰器实际上是Python的一个语法糖，当我们使用一个装饰器的时候，实际上在编译期间会被编译成为一个赋值语句。">
<meta property="article:published_time" content="2020-04-03T15:55:00.000Z">
<meta property="article:modified_time" content="2020-04-09T15:07:27.881Z">
<meta property="article:author" content="Laomo.">
<meta property="article:tag" content="python教程">
<meta name="twitter:card" content="summary">
  
    <link rel="alternate" href="/atom.xml" title="Laomo 的后院" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  
<link rel="stylesheet" href="/css/style.css">

<meta name="generator" content="Hexo 4.2.0"></head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">Laomo 的后院</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://yoursite.com"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main"><article id="post-搞定Python装饰器（一）" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2020/04/03/%E6%90%9E%E5%AE%9APython%E8%A3%85%E9%A5%B0%E5%99%A8%EF%BC%88%E4%B8%80%EF%BC%89/" class="article-date">
  <time datetime="2020-04-03T15:55:00.000Z" itemprop="datePublished">2020-04-03</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      搞定 Python 装饰器（一）
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <p>来聊一聊 Python 中的一个很有意思的特性——<strong>装饰器</strong></p>
<blockquote>
<p>Python 装饰器，实际上是一个用于接收被装饰函数的一个可调用对象。</p>
</blockquote>
<p>为什么说是可调用对象呢，因为在Python中，任何一个实现了<code>__call__</code>方法的对象都能被作为可调用对象，所以，装饰器可以是<strong>类</strong>，<strong>对象</strong>或者函数。</p>
<p>回到正题，装饰器实际上是Python的一个语法糖，当我们使用一个装饰器的时候，实际上在编译期间会被编译成为一个赋值语句。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@timeit</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">foo</span><span class="params">()</span>:</span></span><br><span class="line">    <span class="keyword">for</span> _ <span class="keyword">in</span> range(<span class="number">5013</span>):</span><br><span class="line">        <span class="keyword">pass</span></span><br><span class="line">    </span><br><span class="line"><span class="comment"># 编译后：</span></span><br><span class="line"><span class="comment"># foo = timeit(foo)</span></span><br></pre></td></tr></table></figure>

<p>所以说，我们在 foo 上面盖上一个修饰器，实际上和调用这个装饰器传入这个函数再赋值给这个函数，没啥子区别。不信？来看看字节码：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># @timeit</span></span><br><span class="line"><span class="comment"># def foo():</span></span><br><span class="line"><span class="comment">#     pass</span></span><br><span class="line"></span><br><span class="line"><span class="meta">&gt;&gt;&gt; </span>dis.dis(<span class="string">'@timeit\ndef foo():pass'</span>)</span><br><span class="line">  <span class="number">1</span>           <span class="number">0</span> LOAD_NAME                <span class="number">0</span> (timeit <span class="comment"># 加载 timeit 对象</span></span><br><span class="line"></span><br><span class="line">  <span class="number">2</span>           <span class="number">2</span> LOAD_CONST               <span class="number">0</span> (&lt;code object foo at <span class="number">0x0000021C895F7450</span>, file <span class="string">"&lt;dis&gt;"</span>, line <span class="number">1</span>&gt;)</span><br><span class="line">              <span class="number">4</span> LOAD_CONST               <span class="number">1</span> (<span class="string">'foo'</span>)</span><br><span class="line">              <span class="number">6</span> MAKE_FUNCTION            <span class="number">0</span>	      </span><br><span class="line">              <span class="number">8</span> CALL_FUNCTION            <span class="number">1</span>        <span class="comment"># 调用 timeit 方法</span></span><br><span class="line">             <span class="number">10</span> STORE_NAME               <span class="number">1</span> (foo)  <span class="comment"># 重新给 foo 赋值</span></span><br><span class="line">             <span class="number">12</span> LOAD_CONST               <span class="number">2</span> (<span class="literal">None</span>)</span><br></pre></td></tr></table></figure>



<h2 id="如何编写一个装饰器"><a href="#如何编写一个装饰器" class="headerlink" title="如何编写一个装饰器"></a>如何编写一个装饰器</h2><p>我们已经知道了，装饰器就是一个<strong>返回一个函数</strong>的可调用对象。既然知道了原理，写起来就很简单了。</p>
<p>接下来，我们就一步一步实现一个程序计时器——<code>timeit</code></p>
<p>首先，装饰器是一个可调用对象，一般对于可调用对象我们都会选择使用函数。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">timeit</span><span class="params">(func)</span>:</span></span><br><span class="line">    <span class="comment"># Do something...</span></span><br><span class="line">    <span class="keyword">pass</span></span><br></pre></td></tr></table></figure>

<p>装饰器不仅要可以调用，还需要返回一个可调用对象，这个可调用对象一般拥有下面几个特征：</p>
<ol>
<li>返回和被装饰函数相同（或者同类型）的返回值</li>
<li>形式参数尽可能符合被修饰的函数的形式参数</li>
<li>在调用被装饰函数的基础上，做一些别的事情</li>
</ol>
<p>这个可调用对象有一点特殊，需要访问到外面那层函数的域，以获得被装饰的函数并调用。对于这种情况，我们会选择使用闭包。</p>
<p>在timeit里面编写闭包函数，该函数的形参应该是与被装饰函数相同，但是，每个函数的形参可能都不一样，所以对于这种不确定参数，我们需要用<strong>变参</strong>，python 中的变参表示有 <code>*</code>和<code>**</code>两种表示，分别表示可变位置参数和可选关键字参数。</p>
<p><strong><em>这个闭包，就是装饰器本体，timeit 函数只不过是一个壳，用于释放装饰函数。</em></strong></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">timeit</span><span class="params">(func)</span>:</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">wrapper</span><span class="params">(*args, **kwargs)</span>:</span></span><br><span class="line">    	<span class="comment"># Do something...</span></span><br><span class="line">    	<span class="keyword">pass</span></span><br><span class="line">    <span class="keyword">return</span> wrapper <span class="comment"># 返回（释放）装饰器</span></span><br></pre></td></tr></table></figure>

<p><strong><em>我们调用被装饰过后的函数，实际上是调用释放出来的函数</em></strong></p>
<p>接下来，我们只要编写计时器函数的逻辑即可</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># mytimer.py</span></span><br><span class="line"><span class="keyword">import</span> time</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">timeit</span><span class="params">(func)</span>:</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">wrapper</span><span class="params">(*args, **kwargs)</span>:</span></span><br><span class="line">        start = time.time() * <span class="number">1000</span> <span class="comment">#转换成毫秒</span></span><br><span class="line">        </span><br><span class="line">        <span class="keyword">try</span>:</span><br><span class="line">            rtn = func()</span><br><span class="line">        <span class="keyword">except</span>:</span><br><span class="line">            <span class="keyword">raise</span></span><br><span class="line">        <span class="keyword">finally</span>:</span><br><span class="line">            print(<span class="string">'[ time = %s ms ]'</span> % (time.time() * <span class="number">1000</span> - start))</span><br><span class="line">        </span><br><span class="line">        <span class="keyword">return</span> rtn</span><br><span class="line">	<span class="keyword">return</span> wrapper</span><br></pre></td></tr></table></figure>

<p>好了，我们的timeit装饰器搞定了，来试试吧</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># test.py</span></span><br><span class="line"><span class="keyword">from</span> mytimer <span class="keyword">import</span> timeit</span><br><span class="line"></span><br><span class="line"><span class="meta">@timeit</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">foo</span><span class="params">()</span>:</span></span><br><span class="line">    <span class="keyword">for</span> _ <span class="keyword">in</span> range(<span class="number">5013</span>):</span><br><span class="line">        <span class="keyword">pass</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">'__main__'</span>:</span><br><span class="line">    foo()</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ python test.py</span><br><span class="line">[ time &#x3D; 1.00048828125 ms ]</span><br></pre></td></tr></table></figure>

<p>看起来运行得不错，那么接下来，我们将改进 timeit，让其能够选择是以毫秒输出还是以秒输出。</p>
<h2 id="如何编写有参装饰器"><a href="#如何编写有参装饰器" class="headerlink" title="如何编写有参装饰器"></a>如何编写有参装饰器</h2><p>接下来教大伙一个很简单的方法来还原装饰器语法糖，屡试不爽。</p>
<p>对于这样的装饰器使用，会被转换成下面的样子</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@timeit(True)</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">f</span><span class="params">()</span>:</span></span><br><span class="line">	<span class="keyword">pass</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 会被转换成下面的样子</span></span><br><span class="line"><span class="comment"># f = timeit(True)(f)</span></span><br></pre></td></tr></table></figure>

<p>为了将装饰器语法糖转换成赋值语句，可以使用下面那个公式</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">被装饰函数 &#x3D; 装饰器声明 ( 被装饰函数 )</span><br></pre></td></tr></table></figure>
<p><em>装饰器声明，即‘@’右侧的内容</em></p>
<p>根据转换出来的<code>f = timeit(True)(f)</code>可以知道，我们需要一个接受一个<code>bool</code>类型的可调用对象，在这个对象被调用后，返回另一个可调用对象，这个对象接受传入的<code>f</code>，最后再返回装饰器本体。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">timeit</span><span class="params">(use_ms)</span>:</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">wrapper</span><span class="params">(func)</span>:</span></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">inner_wrapper</span><span class="params">(*args, **kwargs)</span>:</span></span><br><span class="line">            <span class="comment"># Do something...</span></span><br><span class="line">            <span class="keyword">pass</span></span><br><span class="line">        <span class="keyword">return</span> inner_wrapper</span><br><span class="line">    <span class="keyword">return</span> wrapper</span><br></pre></td></tr></table></figure>

<p>现在，我们可以修改我们的 <code>mytimer.py</code>，让 timeit 装饰器接受一个<code>bool</code>参数</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># mytimer.py</span></span><br><span class="line"><span class="keyword">import</span> time</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">timeit</span><span class="params">(use_ms :bool)</span>:</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">wrapper</span><span class="params">(func)</span>:</span></span><br><span class="line">        <span class="function"><span class="keyword">def</span> <span class="title">inner_wrapper</span><span class="params">(*args, **kwargs)</span>:</span></span><br><span class="line">            p = <span class="number">1000</span> <span class="keyword">if</span> use_ms <span class="keyword">else</span> <span class="number">1</span></span><br><span class="line">            s = <span class="string">'ms'</span> <span class="keyword">if</span> use_ms <span class="keyword">else</span> <span class="string">'s'</span></span><br><span class="line">            start = time.time() * p</span><br><span class="line">            </span><br><span class="line">            <span class="keyword">try</span>:</span><br><span class="line">                rtn = func()</span><br><span class="line">            <span class="keyword">except</span>:</span><br><span class="line">                <span class="keyword">raise</span></span><br><span class="line">            <span class="keyword">finally</span>:</span><br><span class="line">                print(<span class="string">'[ time = %s %s ]'</span> % (time.time() * p - start, s))</span><br><span class="line">                      </span><br><span class="line">            <span class="keyword">return</span> rtn</span><br><span class="line">        <span class="keyword">return</span> inner_wrapper</span><br><span class="line">    <span class="keyword">return</span> wrapper</span><br></pre></td></tr></table></figure>

<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># test_t.py</span></span><br><span class="line"><span class="keyword">from</span> mytimer <span class="keyword">import</span> timeit</span><br><span class="line"></span><br><span class="line"><span class="meta">@timeit(True)</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">foo</span><span class="params">()</span>:</span></span><br><span class="line">    <span class="keyword">for</span> _ <span class="keyword">in</span> range(<span class="number">5013</span>):</span><br><span class="line">        <span class="keyword">pass</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">'__main__'</span>:</span><br><span class="line">    foo()</span><br></pre></td></tr></table></figure>

<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># test_f.py</span></span><br><span class="line"><span class="keyword">from</span> mytimer <span class="keyword">import</span> timeit</span><br><span class="line"></span><br><span class="line"><span class="meta">@timeit(false)</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">foo</span><span class="params">()</span>:</span></span><br><span class="line">    <span class="keyword">for</span> _ <span class="keyword">in</span> range(<span class="number">5013</span>):</span><br><span class="line">        <span class="keyword">pass</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">'__main__'</span>:</span><br><span class="line">    foo()</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">$ python test_t.py</span><br><span class="line">[ time &#x3D; 1.04 ms ]</span><br><span class="line"></span><br><span class="line">$ python test_f.py</span><br><span class="line">[ time &#x3D; 0.0014 s ]</span><br></pre></td></tr></table></figure>

<p>其他地方，就不多赘述了。</p>
<p>下一篇文章讲一讲对象类型的装饰器</p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2020/04/03/%E6%90%9E%E5%AE%9APython%E8%A3%85%E9%A5%B0%E5%99%A8%EF%BC%88%E4%B8%80%EF%BC%89/" data-id="ck8swb30f0009wds6ee589f4n" class="article-share-link">Share</a>
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/python%E6%95%99%E7%A8%8B/" rel="tag">python教程</a></li></ul>

    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2020/04/04/%E3%80%90%E5%9B%BE%E7%89%87%E6%B5%8B%E8%AF%95%E3%80%91%E5%8F%AF%E7%88%B1%E7%9A%84%E5%90%92%E5%84%BF/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          【图片测试】可爱的吒儿
        
      </div>
    </a>
  
  
    <a href="/2020/04/03/%E6%88%91%E6%8A%8ATermux%E6%95%B4%E5%BA%9F%E4%BA%86/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">我把Termux整废了</div>
    </a>
  
</nav>

  
</article>

</section>
        
          <aside id="sidebar">
  
    

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="/tags/SAIL%E5%BC%80%E5%8F%91%E6%97%A5%E5%BF%97/" rel="tag">SAIL开发日志</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/python%E6%95%99%E7%A8%8B/" rel="tag">python教程</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%93%AA%E5%90%92%E7%9B%B8%E5%85%B3/" rel="tag">哪吒相关</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E6%B5%81%E6%B0%B4%E8%B4%A6/" rel="tag">流水账</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E8%8A%B1%E9%87%8C%E8%83%A1%E5%93%A8/" rel="tag">花里胡哨</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="/tags/SAIL%E5%BC%80%E5%8F%91%E6%97%A5%E5%BF%97/" style="font-size: 10px;">SAIL开发日志</a> <a href="/tags/python%E6%95%99%E7%A8%8B/" style="font-size: 20px;">python教程</a> <a href="/tags/%E5%93%AA%E5%90%92%E7%9B%B8%E5%85%B3/" style="font-size: 10px;">哪吒相关</a> <a href="/tags/%E6%B5%81%E6%B0%B4%E8%B4%A6/" style="font-size: 15px;">流水账</a> <a href="/tags/%E8%8A%B1%E9%87%8C%E8%83%A1%E5%93%A8/" style="font-size: 10px;">花里胡哨</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/04/">April 2020</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2020/04/05/%E3%80%90LaTeX%E6%B5%8B%E8%AF%95%E3%80%91%E4%B8%80%E4%BA%9B%E8%91%97%E5%90%8D%E7%9A%84%E5%85%AC%E5%BC%8F/">【LaTeX测试】一些著名的公式</a>
          </li>
        
          <li>
            <a href="/2020/04/04/%E6%90%9E%E5%AE%9APython%E8%A3%85%E9%A5%B0%E5%99%A8%EF%BC%88%E4%B8%89%EF%BC%89%E5%AE%9E%E7%8E%B0property%E7%B1%BB/">搞定Python装饰器（三）实现property类</a>
          </li>
        
          <li>
            <a href="/2020/04/04/%E6%90%9E%E5%AE%9APython%E8%A3%85%E9%A5%B0%E5%99%A8%EF%BC%88%E4%BA%8C%EF%BC%89/">搞定Python装饰器（二）</a>
          </li>
        
          <li>
            <a href="/2020/04/04/%E3%80%90%E5%9B%BE%E7%89%87%E6%B5%8B%E8%AF%95%E3%80%91%E5%8F%AF%E7%88%B1%E7%9A%84%E5%90%92%E5%84%BF/">【图片测试】可爱的吒儿</a>
          </li>
        
          <li>
            <a href="/2020/04/03/%E6%90%9E%E5%AE%9APython%E8%A3%85%E9%A5%B0%E5%99%A8%EF%BC%88%E4%B8%80%EF%BC%89/">搞定 Python 装饰器（一）</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2020 Laomo.<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>


  
<link rel="stylesheet" href="/fancybox/jquery.fancybox.css">

  
<script src="/fancybox/jquery.fancybox.pack.js"></script>




<script src="/js/script.js"></script>




  </div>
</body>
</html>